
package com.example.caorl.job1.conc0302.atomic;

public class AtomicMain {

    public static void main(String[] args) {
        final SyncCount syncCount = new SyncCount();
        final AtomicCount atomicCount = new AtomicCount();
        final Count notSyncCount = new Count();
        for (int i = 0; i < 100; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int j = 0; j < 10000; j++) {
                        syncCount.add();
                        atomicCount.add();
                        notSyncCount.add();
                        if (j==999) {
                            System.out.println("last add"); //检查所有线程执行完毕
                        }
                    }
                }
            }).start();
        }

/*        try {
            Thread.sleep(10000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        System.out.println("syncCount=" + syncCount.getNum()); //等于100000
        System.out.println("atomicCount=" + atomicCount.getNum()); //等于100000
        System.out.println("notSyncCount=" + notSyncCount.getNum()); //不等于100000
    }

}
